/**
 * @Author Fish Paradise
 * @Description
 * @Date 2019/1/30  15:15
 **/
public abstract class Method {
    private String name;
    private Method next;

    public Method(String name) {
        this.name = name;
    }

    public Method setNext(Method next){
        this.next = next;
        return next;
    }

    public final void support(Problem pb){
        if(resolve(pb)){
            done(pb);
        }else if(next != null){
            next.support(pb);
        }else {
            failed(pb);
        }
    }

    protected abstract boolean resolve(Problem pb);

    protected void done(Problem pb){
        System.out.println(pb + "is done by " + this + ".");
    }

    protected void failed(Problem pb){
        System.out.println(pb + "can not be done");
    }

    @Override
    public String toString() {
        return "Method{" +
                "name='" + name + '\'' +
                '}';
    }
}
